package baseFx.serialization.json.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class NumberSerializer extends JsonSerializer<Number> {
    @Override
    public void serialize(Number number, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String str = String.valueOf(number);
        if (str.length() > 16) {
            jsonGenerator.writeString(str);
        } else {
            jsonGenerator.writeNumber(str);
        }
    }
}
